Namespace("sketch.framework");

(function(fwk) {
    fwk.ActionBag = klass(null, {
        _constructor: function(){
            this._data = {};
        },

        add: function(groupName, commandConstructor, commandImage){
            if (this._data[groupName] === undefined){
                this._data[groupName] = [];
            }

            this._data[groupName].push({commandConstructor: commandConstructor, image: commandImage});
        },

        iterate: function(groupCallback, actionCallback){
            for (var i in this._data){
                if (groupCallback != null){
                    groupCallback(i);
                }
                for (var j = 0, k = this._data[i].length; j < k; ++j){
                    var item = this._data[i][j];
                    actionCallback(item.commandConstructor, item.image, i);
                }
            }
        },

        mergeWith: function(other){
            var that = this;
            other.iterate(null, function(commandConstructor, image, groupName){
                that.add(groupName, commandConstructor, image);
            });
            return that;
        }
    });
})(sketch.framework);